fix(bedrock): add 'prompt is too long' to context window overflow mes… #1663
+27
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Claude Opus 4.6 via Bedrock returns a different error message when the context window is exceeded:
This message was not recognized by the Bedrock provider's
BEDROCK_CONTEXT_WINDOW_OVERFLOW_MESSAGESlist, causing the agent to raise a rawClientErrorinstead ofContextWindowOverflowException. This prevents the agent'sreduce_context()recovery mechanism from triggering.The Anthropic direct API provider already handles this message (
"prompt is too long:"inAnthropicModel.OVERFLOW_MESSAGES), but the Bedrock provider was missing it.Fix: Add
"prompt is too long"toBEDROCK_CONTEXT_WINDOW_OVERFLOW_MESSAGES.Related Issues
N/A
Documentation PR
N/A
Type of Change
Bug fix
Testing
Added a parametrized test (
test_stream_context_window_overflow) covering all 4 overflow message variants, including the new"prompt is too long"message.hatch run prepareResults: 1764 passed, 4 skipped, 0 failures.
Checklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.